package javawdw.security.dao.impl;

import javawdw.security.dao.RoleResourceDao;
import javawdw.security.entity.RoleResource;

import org.hibernate.Query;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataRetrievalFailureException;

public class RoleResourceDaoImpl extends AbstractDaoImpl<RoleResource> implements RoleResourceDao {
	public void deleteByResourceId(String resourceId) throws DataAccessException,
			DataRetrievalFailureException, IllegalArgumentException {
			String hql = "DELETE FROM RoleResource WHERE resource.id=:resourceId";
			Query query = getSession().createQuery(hql);
			query.setString("resourceId", resourceId);
			query.executeUpdate();
	}

	@Override
	public void deleteByRoleId(String roleId) throws DataAccessException,
			DataRetrievalFailureException, IllegalArgumentException {
		String hql = "DELETE FROM RoleResource WHERE role.id=:roleId";
		Query query = getSession().createQuery(hql);
		query.setString("roleId", roleId);
		query.executeUpdate();
	}
}